// splice可以改变原数组
// slice不改变原数组


var rotate = function (nums, k) {
  let len = nums.length;
  if (k % len === 0) return nums;
  else {
    let sliceArr = nums.splice(k + 1, len - k);
    let newArr = [...sliceArr, ...nums];
    nums = newArr.map((item, index) => {
      nums[index] = item;
    });
    console.log(nums);
  }
};

// const res = rotate([1, 2, 3, 4, 5, 6, 7], 3);
// console.log(res);
rotate([1, 2, 3, 4, 5, 6, 7], 3);
